﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Windows.Forms;
using System.Windows.Forms.Integration;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using YArchitech.Controls;
using YArchitech.DataModel;
using YArchitech.LIB;
using YArchitech.LIB.YJKControls;

namespace YJKFurniture.LayoutFurnitures
{
	public partial class LayFurnitureForm : System.Windows.Forms.Form
	{
		public LayFurnitureForm(ExternalCommandData commandData)
		{
			this.InitializeComponent();
			//base.Icon = Resource.YArchitechIcon;
			this.m_uiApp = commandData.Application;
			this.m_uiDoc = this.m_uiApp.ActiveUIDocument;
			this.m_CurrentDoc = this.m_uiDoc.Document;
			this.LoadData();
			this.InitFurniture();
		}

		private void LayFurnitureForm_Load(object sender, EventArgs e)
		{
			this.InitUserSetting(sender, e);
			this.SetBtnEnabled();
		}

		private void SetBtnEnabled()
		{
			if (this.rad2D.Checked)
			{
				this.txtRelativeHeight.Text = "0.0";
				this.txtRelativeHeight.Enabled = false;
				this.btnPriview.Enabled = false;
			}
			else if (this.rad3D.Checked)
			{
				this.txtRelativeHeight.Enabled = true;
				this.btnPriview.Enabled = true;
			}
			if (this.lvwFurnitureImage.SelectedItems == null || this.lvwFurnitureImage.SelectedItems.Count == 0)
			{
				this.btnLayoutFree.Enabled = false;
				this.btnLayoutAlongFurniture.Enabled = false;
				this.btnLayoutAlongWall.Enabled = false;
				return;
			}
			this.btnLayoutFree.Enabled = true;
			this.btnLayoutAlongFurniture.Enabled = true;
			this.btnLayoutAlongWall.Enabled = true;
		}

		private void LoadData()
		{
			DataTable furniture = this.m_sfdr.GetFurniture();
			if (furniture == null)
			{
				return;
			}
			foreach (object obj in furniture.Rows)
			{
				DataRow dataRow = (DataRow)obj;
				try
				{
					this.m_lstFurnitureInfo.Add(new FurnitureInfo(Convert.ToInt32(dataRow["Id"]), dataRow["Name"].ToString(), dataRow["Family"].ToString(), dataRow["FamilySymbol"].ToString(), dataRow["Category"].ToString(), dataRow["Version"].ToString()));
				}
				catch (Exception)
				{
				}
			}
		}

		private void InitFurniture()
		{
			this.lstboxFurnitureStyle.SetSelected(0, true);
		}

		private void LoadImage()
		{
			try
			{
				this.imgLst.Images.Clear();
				this.lvwFurnitureImage.Clear();
				List<FurnitureInfo> list = new List<FurnitureInfo>();
				if (this.radCurrentProject.Checked)
				{
					List<Element> lstFamilySymbol = this.FamilySymbolCollector();
					List<FurnitureInfo> list2 = this.FurnitureFactory(lstFamilySymbol);
					list = list2;
				}
				else
				{
					list = this.m_lstFurnitureInfo;
				}
				if (list != null)
				{
					this.GetAndShowImage(list);
					if (this.lvwFurnitureImage.Items.Count > 0)
					{
						this.lvwFurnitureImage.Select();
						this.lvwFurnitureImage.Items[0].Selected = true;
					}
					if (this.m_bPreview)
					{
						this.ShowPreview();
					}
					this.SetBtnEnabled();
				}
			}
			catch
			{
			}
		}

		private void GetAndShowImage(List<FurnitureInfo> lstFurnitureInfo)
		{
			string value = this.lstboxFurnitureStyle.SelectedItem.ToString();
			if (this.rad2D.Checked)
			{
				int num = 0;
				using (List<FurnitureInfo>.Enumerator enumerator = lstFurnitureInfo.GetEnumerator())
				{
					while (enumerator.MoveNext())
					{
						FurnitureInfo furnitureInfo = enumerator.Current;
						if (furnitureInfo.m_b2D && furnitureInfo.m_strCategory.Contains(value))
						{
							try
							{
								string strFamilySymbol = furnitureInfo.m_strFamilySymbol;
								Image image;
								if (this.radCurrentProject.Checked)
								{
									FamilySymbol fs = furnitureInfo.m_fs;
									if (File.Exists(Path.Combine(Product.FamilyImageLocation, "EquipmentFurniture", strFamilySymbol + ".jpg")))
									{
										image = Image.FromFile(Path.Combine(Product.FamilyImageLocation, "EquipmentFurniture", strFamilySymbol + ".jpg"), true);
									}
									else if (File.Exists(Path.Combine(Product.FamilyImageLocation, "EquipmentFurniture", strFamilySymbol + " - 楼层平面 - 参照标高.jpg")))
									{
										image = Image.FromFile(Path.Combine(Product.FamilyImageLocation, "EquipmentFurniture", strFamilySymbol + " - 楼层平面 - 参照标高.jpg"), true);
									}
									else
									{
										image = this.Get2DImageFromFamily(fs, strFamilySymbol);
									}
								}
								else
								{
									image = Image.FromFile(Path.Combine(Product.FamilyImageLocation, "EquipmentFurniture", strFamilySymbol + ".jpg"), true);
								}
								if (image != null)
								{
									this.imgLst.Images.Add(image);
									ListViewItem listViewItem = new ListViewItem();
									listViewItem.ImageIndex = num;
									listViewItem.Text = strFamilySymbol;
									listViewItem.Tag = furnitureInfo;
									this.lvwFurnitureImage.Items.Add(listViewItem);
									num++;
								}
							}
							catch (Exception)
							{
							}
						}
					}
					return;
				}
			}
			int num2 = 0;
			foreach (FurnitureInfo furnitureInfo2 in lstFurnitureInfo)
			{
				if (!furnitureInfo2.m_b2D && furnitureInfo2.m_strCategory.Contains(value))
				{
					try
					{
						string strFamilySymbol2 = furnitureInfo2.m_strFamilySymbol;
						Image image2;
						if (this.radCurrentProject.Checked)
						{
							FamilySymbol fs2 = furnitureInfo2.m_fs;
							if (File.Exists(Path.Combine(Product.FamilyImageLocation, "EquipmentFurniture", strFamilySymbol2 + ".jpg")))
							{
								image2 = Image.FromFile(Path.Combine(Product.FamilyImageLocation, "EquipmentFurniture", strFamilySymbol2 + ".jpg"), true);
							}
							else if (File.Exists(Path.Combine(Product.FamilyImageLocation, "EquipmentFurniture", strFamilySymbol2 + " - 三维视图 - 视图 1.jpg")))
							{
								image2 = Image.FromFile(Path.Combine(Product.FamilyImageLocation, "EquipmentFurniture", strFamilySymbol2 + " - 三维视图 - 视图 1.jpg"), true);
							}
							else
							{
								image2 = this.Get3DImageFromFamily(fs2, strFamilySymbol2);
							}
						}
						else
						{
							image2 = Image.FromFile(Path.Combine(Product.FamilyImageLocation, "EquipmentFurniture", strFamilySymbol2 + ".jpg"), true);
						}
						if (image2 != null)
						{
							this.imgLst.Images.Add(image2);
							ListViewItem listViewItem2 = new ListViewItem();
							listViewItem2.ImageIndex = num2;
							listViewItem2.Text = strFamilySymbol2;
							listViewItem2.Tag = furnitureInfo2;
							this.lvwFurnitureImage.Items.Add(listViewItem2);
							num2++;
						}
					}
					catch (Exception)
					{
					}
				}
			}
		}

		private Image Get2DImageFromFamily(FamilySymbol famSy, string imageName)
		{
			Image result = null;
			try
			{
				Document document = this.m_CurrentDoc.EditFamily(famSy.Family);
				ImageExportOptions imageExportOptions = new ImageExportOptions();
                imageExportOptions.FitDirection = FitDirectionType.Vertical;
                imageExportOptions.HLRandWFViewsFileType = ImageFileType.JPEGLossless;
                imageExportOptions.ImageResolution = ImageResolution.DPI_600;
				imageExportOptions.ShouldCreateWebSite = false;
                imageExportOptions.ExportRange = ExportRange.SetOfViews;
                imageExportOptions.ZoomType = ZoomFitType.Zoom;
				imageExportOptions.Zoom = 7;



				imageExportOptions.FilePath = Path.Combine(Product.FamilyImageLocation, "EquipmentFurniture", imageName);
				ElementId elementId = null;
				FilteredElementCollector filteredElementCollector = new FilteredElementCollector(document);
                FilteredElementIterator elementIterator = filteredElementCollector.OfClass(typeof(Autodesk.Revit.DB.View)).GetElementIterator();
				elementIterator.Reset();
				while (elementIterator.MoveNext())
				{
					Element element = elementIterator.Current;
                    Autodesk.Revit.DB.View view = element as Autodesk.Revit.DB.View;
                    if (view != null && !view.IsTemplate && (int)view.ViewType == 1 && view.Name == "参照标高")
					{
						elementId = view.Id;
						break;
					}
				}
				if (null != elementId)
				{
					imageExportOptions.SetViewsAndSheets(new List<ElementId>
					{
						elementId
					});
					document.ExportImage(imageExportOptions);
					result = Image.FromFile(imageExportOptions.FilePath + " - 楼层平面 - 参照标高.jpg", true);
				}
			}
			catch
			{
			}
			return result;
		}

		private Image Get3DImageFromFamily(FamilySymbol famSy, string imageName)
		{
			Image result = null;
			try
			{
				Document document = this.m_CurrentDoc.EditFamily(famSy.Family);
				ImageExportOptions imageExportOptions = new ImageExportOptions();
                imageExportOptions.FitDirection = FitDirectionType.Vertical;
                imageExportOptions.HLRandWFViewsFileType = ImageFileType.JPEGLossless;
                imageExportOptions.ImageResolution = ImageResolution.DPI_600;
				imageExportOptions.ShouldCreateWebSite = false;
                imageExportOptions.ExportRange = ExportRange.SetOfViews;
                imageExportOptions.ZoomType = ZoomFitType.Zoom;
				imageExportOptions.Zoom = 2;

				imageExportOptions.FilePath = Path.Combine(Product.FamilyImageLocation, "EquipmentFurniture", imageName);
				ElementId elementId = null;
				FilteredElementCollector filteredElementCollector = new FilteredElementCollector(document);
                FilteredElementIterator elementIterator = filteredElementCollector.OfClass(typeof(Autodesk.Revit.DB.View)).GetElementIterator();
				elementIterator.Reset();
                Autodesk.Revit.DB.View view = null;
				while (elementIterator.MoveNext())
				{
					Element element = elementIterator.Current;
                    view = (element as Autodesk.Revit.DB.View);
                    if (view != null && !view.IsTemplate && (int)view.ViewType == 4)
					{
						elementId = view.Id;
						break;
					}
				}
				using (Transaction transaction = new Transaction(document, "Set View3D property"))
				{
					try
					{
						transaction.Start();
						XYZ xyz = new XYZ(-1.0, 1.0, -1.0);
						XYZ xyz2 = xyz * 10.0;
						XYZ xyz3 = xyz;
						XYZ xyz4 = new XYZ(xyz.X, xyz.Y, 0.0);
						xyz4 = this.RotateTo(xyz4, -Math.PI*.5, XYZ.BasisZ);
						XYZ xyz5 = this.RotateTo(xyz3, Math.PI*.5, xyz4);
						ViewOrientation3D orientation = new ViewOrientation3D(xyz2, xyz5, xyz3);
						(view as View3D).SetOrientation(orientation);
					}
					catch (Exception)
					{
						transaction.RollBack();
					}
				}
				if (null != elementId)
				{
					imageExportOptions.SetViewsAndSheets(new List<ElementId>
					{
						elementId
					});
					document.ExportImage(imageExportOptions);
					result = Image.FromFile(imageExportOptions.FilePath + " - 三维视图 - 视图 1.jpg", true);
				}
			}
			catch (Exception)
			{
			}
			return result;
		}

		private XYZ RotateTo(XYZ List, double angle, XYZ axis)
		{
			Transform transform = Transform.CreateRotationAtPoint(axis, angle, new XYZ(0.0, 0.0, 0.0));
			return transform.OfPoint(List);
		}

		private List<Element> FamilySymbolCollector()
		{
			FilteredElementCollector filteredElementCollector = new FilteredElementCollector(this.m_CurrentDoc);
			filteredElementCollector.OfClass(typeof(FamilySymbol)).OfCategory(BuiltInCategory.OST_Furniture);
			return filteredElementCollector.ToList<Element>();
		}

		private List<FurnitureInfo> FurnitureFactory(List<Element> lstFamilySymbol)
		{
			if (lstFamilySymbol == null)
			{
				return null;
			}
			List<FurnitureInfo> list = new List<FurnitureInfo>();
			foreach (Element element in lstFamilySymbol)
			{
				FamilySymbol familySymbol = element as FamilySymbol;
				string category;
				if (familySymbol.FamilyName.Contains("桌"))
				{
					if (familySymbol.FamilyName.Contains("办公") || familySymbol.FamilyName.Contains("工位") || (familySymbol.FamilyName.Contains("电脑桌") && !familySymbol.FamilyName.Contains("椅")))
					{
						category = "桌子,办公桌组合";
					}
					else if (familySymbol.FamilyName.Contains("会议桌"))
					{
						category = "桌子,会议桌组合";
					}
					else
					{
						category = "桌子";
					}
				}
				else if (familySymbol.FamilyName.Contains("前台") || familySymbol.FamilyName.Contains("大班台"))
				{
					category = "前台组合";
				}
				else if (familySymbol.FamilyName.Contains("床"))
				{
					category = "床";
				}
				else if (familySymbol.FamilyName.Contains("柜"))
				{
					category = "柜子";
				}
				else if (familySymbol.FamilyName.Contains("椅"))
				{
					category = "椅子";
				}
				else if (familySymbol.FamilyName.Contains("沙发"))
				{
					category = "沙发";
				}
				else if (familySymbol.FamilyName.Contains("几"))
				{
					category = "茶几";
				}
				else
				{
					category = "其他";
				}
				FurnitureInfo furnitureInfo = new FurnitureInfo(familySymbol, category);
				if (!list.Any((FurnitureInfo item) => item.m_strFamily == furnitureInfo.m_strFamily))
				{
					list.Add(furnitureInfo);
				}
			}
			return list;
		}

		private void radFamilyLib_CheckedChanged(object sender, EventArgs e)
		{
			this.LoadImage();
		}

		private void LayFurnitureForm_KeyDown(object sender, KeyEventArgs e)
		{
			if (e.KeyCode == Keys.Escape)
			{
				base.Close();
			}
		}

		private void SetUserData()
		{
			this.m_userSetting.ReloadFile();
			this.m_userSetting.WriteValue("FurnitureLayout", "IsCurrentPro", this.radCurrentProject.Checked.ToString());
			this.m_userSetting.WriteValue("FurnitureLayout", "Is3D", this.rad3D.Checked.ToString());
			this.m_userSetting.WriteValue("FurnitureLayout", "FurnitureType", this.lstboxFurnitureStyle.SelectedItem.ToString());
			this.m_userSetting.WriteValue("FurnitureLayout", "FurnitureStyle", this.lvwFurnitureImage.SelectedItems[0].Index.ToString());
			this.m_userSetting.WriteValue("FurnitureLayout", "RelativeHeight", this.txtRelativeHeight.Text);
			this.m_userSetting.WriteValue("FurnitureLayout", "PreviewOpen", this.m_bPreview.ToString());
		}

		private void InitUserSetting(object sender, EventArgs e)
		{
			try
			{
				string value = this.m_userSetting.GetValue("FurnitureLayout", "IsCurrentPro");
				if (value == "True")
				{
					this.radFamilyLib.Checked = false;
					this.radCurrentProject.Checked = true;
				}
				else
				{
					this.radFamilyLib.Checked = true;
					this.radCurrentProject.Checked = false;
				}
				string value2 = this.m_userSetting.GetValue("FurnitureLayout", "Is3D");
				if (value2 == "True")
				{
					this.rad3D.Checked = true;
					this.rad2D.Checked = false;
				}
				else
				{
					this.rad2D.Checked = true;
					this.rad3D.Checked = false;
				}
				string value3 = this.m_userSetting.GetValue("FurnitureLayout", "FurnitureType");
				if (value3 == "" || value3 == null)
				{
					this.lstboxFurnitureStyle.SetSelected(0, true);
				}
				else
				{
					for (int i = 0; i < this.lstboxFurnitureStyle.Items.Count; i++)
					{
						if (this.lstboxFurnitureStyle.Items[i].ToString() == value3)
						{
							this.lstboxFurnitureStyle.SetSelected(i, true);
							break;
						}
					}
				}
				this.LoadImage();
				string value4 = this.m_userSetting.GetValue("FurnitureLayout", "FurnitureStyle");
				int index = 0;
				if (value4 != "" && value4 != null)
				{
					index = Convert.ToInt32(value4);
				}
				if (this.lvwFurnitureImage.Items != null && this.lvwFurnitureImage.Items.Count != 0)
				{
					this.lvwFurnitureImage.SelectedItems.Clear();
					this.lvwFurnitureImage.Items[index].Selected = true;
				}
				string text = this.m_userSetting.GetValue("FurnitureLayout", "RelativeHeight");
				if (text != "" && text != null)
				{
					text = "0.0";
				}
				this.txtRelativeHeight.Text = text;
				string value5 = this.m_userSetting.GetValue("FurnitureLayout", "PreviewOpen");
				if (value5 == "True" && this.rad3D.Checked)
				{
					this.m_bPreview = false;
					this.btnPriview_Click(sender, e);
				}
			}
			catch
			{
			}
		}

		private void LayFurnitureForm_FormClosing(object sender, FormClosingEventArgs e)
		{
			if (base.DialogResult != DialogResult.OK)
			{
				this.CloseDocuments();
				return;
			}
			this.SetUserData();
			this.CloseDocuments();
		}

		private void lvwFurnitureImage_SelectedIndexChanged(object sender, EventArgs e)
		{
			if (this.lvwFurnitureImage.SelectedItems.Count > 1)
			{
				int index = this.lvwFurnitureImage.SelectedItems[0].Index;
				this.lvwFurnitureImage.SelectedItems.Clear();
				this.lvwFurnitureImage.Items[index].Selected = true;
			}
			this.SetBtnEnabled();
			if (this.m_bPreview)
			{
				FurnitureInfo furnitureInfo = new FurnitureInfo();
				if (this.lvwFurnitureImage.SelectedItems != null && this.lvwFurnitureImage.SelectedItems.Count > 0)
				{
					ListViewItem listViewItem = this.lvwFurnitureImage.SelectedItems[0];
					furnitureInfo = (FurnitureInfo)listViewItem.Tag;
				}
				if (this.radFamilyLib.Checked)
				{
					string strFullName = null;
					if (furnitureInfo != null && furnitureInfo.m_strFamily != null)
					{
						strFullName = Path.Combine(Product.FamilyLocation, this.m_CurrentDoc.Application.VersionNumber, "EquipmentFurniture", furnitureInfo.m_strFamily);
					}
					this.initPreviewControl(strFullName);
					return;
				}
				FamilySymbol fs = furnitureInfo.m_fs;
				this.initPreviewControl(fs);
			}
		}

		private void rad2D_CheckedChanged(object sender, EventArgs e)
		{
			if (this.rad2D.Checked)
			{
				base.Size = new Size(570, 410);
				this.btnPriview.Text = "预览 >>";
				this.m_bPreview = false;
				this.txtRelativeHeight.Enabled = false;
				this.txtRelativeHeight.Text = "0.0";
			}
			this.LoadImage();
		}

		private void lstboxFurnitureStyle_SelectedIndexChanged(object sender, EventArgs e)
		{
			this.LoadImage();
		}

		private void btnPriview_Click(object sender, EventArgs e)
		{
			if (!this.m_bPreview)
			{
				this.ShowPreview();
				this.btnPriview.Text = "预览 <<";
				this.m_bPreview = true;
				base.Size = new Size(810, 410);
				return;
			}
			this.btnPriview.Text = "预览 >>";
			this.m_bPreview = false;
			base.Size = new Size(570, 410);
		}

		private void ShowPreview()
		{
			FurnitureInfo furnitureInfo = new FurnitureInfo();
			if (this.lvwFurnitureImage.SelectedItems == null || this.lvwFurnitureImage.SelectedItems.Count == 0)
			{
				this.Update3DView(null);
				return;
			}
			ListViewItem listViewItem = this.lvwFurnitureImage.SelectedItems[0];
			furnitureInfo = (FurnitureInfo)listViewItem.Tag;
			if (this.radFamilyLib.Checked)
			{
				string strFullName = Path.Combine(Product.FamilyLocation, this.m_CurrentDoc.Application.VersionNumber, "EquipmentFurniture", furnitureInfo.m_strFamily);
				this.initPreviewControl(strFullName);
				return;
			}
			FamilySymbol fs = furnitureInfo.m_fs;
			this.initPreviewControl(fs);
		}

		private void Update3DView(Document subdoc)
		{
			PreviewControl previewControl = this.elemhost3DView.Child as PreviewControl;
			if (subdoc == null)
			{
				if (previewControl != null)
				{
					previewControl.Dispose();
					previewControl = null;
					this.elemhost3DView.Child = null;
				}
				return;
			}
			FilteredElementCollector filteredElementCollector = new FilteredElementCollector(subdoc);
            filteredElementCollector.OfClass(typeof(Autodesk.Revit.DB.View));
            IEnumerable<Autodesk.Revit.DB.View> enumerable = from Element f in filteredElementCollector
                                                             where (f as Autodesk.Revit.DB.View).CanBePrinted
                                                             select f as Autodesk.Revit.DB.View;
            Autodesk.Revit.DB.View view = null;
            foreach (Autodesk.Revit.DB.View view2 in enumerable)
			{
                if ((int)view2.ViewType == 4 && view2.Name == "{3D}")
				{
					view = view2;
					break;
				}
			}
			if (view == null)
			{
                foreach (Autodesk.Revit.DB.View view3 in enumerable)
				{
                    if ((int)view3.ViewType == 4)
					{
						view = view3;
						break;
					}
				}
			}
			if (view == null)
			{
                foreach (Autodesk.Revit.DB.View view4 in enumerable)
				{
                    if ((int)view4.ViewType == 1)
					{
						view = view4;
						break;
					}
				}
			}
			if (view == null)
			{
				if (previewControl != null)
				{
					previewControl.Dispose();
					previewControl = null;
				}
				return;
			}
			if (previewControl != null)
			{
				previewControl.Dispose();
			}
			this.elemhost3DView.Child = new PreviewControl(subdoc, view.Id);
		}

		private void initPreviewControl(FamilySymbol fs)
		{
			Document document = null;
			try
			{
				document = this.m_CurrentDoc.EditFamily(fs.Family);
				this.m_lstDoc.Add(document);
			}
			catch (Exception)
			{
			}
			this.Update3DView(document);
		}

		private void initPreviewControl(string strFullName)
		{
			Document document = this.Get3DPreviewDoc(strFullName);
			this.m_lstDoc.Add(document);
			this.Update3DView(document);
		}

		private Document Get3DPreviewDoc(string strPath)
		{
			Document document = null;
			try
			{
				if (strPath != null)
				{
					document = this.m_uiApp.Application.OpenDocumentFile(strPath);
					this.m_lstDoc.Add(document);
				}
			}
			catch (Exception)
			{
				YJKMessageBox.Show("文档打开出错", MessageBoxButtons.OK);
			}
			return document;
		}

		public void CloseDocuments()
		{
			foreach (Document document in this.m_lstDoc)
			{
				try
				{
					document.Close(false);
				}
				catch (Exception)
				{
				}
			}
		}

		private void txtRelativeHeight_TextChanged(object sender, EventArgs e)
		{
			try
			{
				this.m_dRelativeHeight = Convert.ToDouble(this.txtRelativeHeight.Text);
			}
			catch
			{
			}
		}

		private void btnLayoutFree_Click(object sender, EventArgs e)
		{
			ListViewItem listViewItem = this.lvwFurnitureImage.SelectedItems[0];
			FurnitureInfo furnitureInfo = listViewItem.Tag as FurnitureInfo;
			this.m_strFamilySymbolName = furnitureInfo.m_strFamilySymbol;
			this.m_famSym = furnitureInfo.m_fs;
			this.m_dRelativeHeight = Convert.ToDouble(this.txtRelativeHeight.Text);
			this.m_LayoutStyle = LayoutStyle.LayoutFree;
			base.DialogResult = DialogResult.OK;
		}

		private void btnLayoutAlongWall_Click(object sender, EventArgs e)
		{
			ListViewItem listViewItem = this.lvwFurnitureImage.SelectedItems[0];
			FurnitureInfo furnitureInfo = listViewItem.Tag as FurnitureInfo;
			this.m_strFamilySymbolName = furnitureInfo.m_strFamilySymbol;
			this.m_famSym = furnitureInfo.m_fs;
			this.m_LayoutStyle = LayoutStyle.LayoutAlongWall;
			this.m_dRelativeHeight = Convert.ToDouble(this.txtRelativeHeight.Text);
			LayoutAlongWallForm layoutAlongWallForm = new LayoutAlongWallForm();
			if (layoutAlongWallForm.ShowDialog() == DialogResult.OK)
			{
				this.m_nAlongWallNum = layoutAlongWallForm.m_nFurnitureNum;
				this.m_nAlongWallSpace = layoutAlongWallForm.m_nFurnitureSpace;
				this.m_nAlongWallToFace = layoutAlongWallForm.m_nDistanceToFace;
				this.m_nAlongWallToSide = layoutAlongWallForm.m_nDistanceToSide;
				layoutAlongWallForm.Close();
				base.DialogResult = DialogResult.OK;
			}
		}

		private void btnLayoutAlongFurniture_Click(object sender, EventArgs e)
		{
			ListViewItem listViewItem = this.lvwFurnitureImage.SelectedItems[0];
			FurnitureInfo furnitureInfo = listViewItem.Tag as FurnitureInfo;
			this.m_strFamilySymbolName = furnitureInfo.m_strFamilySymbol;
			this.m_famSym = furnitureInfo.m_fs;
			this.m_LayoutStyle = LayoutStyle.LayoutAlongFurniture;
			this.m_dRelativeHeight = Convert.ToDouble(this.txtRelativeHeight.Text);
			LayoutAlongFurnitureForm layoutAlongFurnitureForm = new LayoutAlongFurnitureForm();
			if (layoutAlongFurnitureForm.ShowDialog() == DialogResult.OK)
			{
				this.m_nAlongFurnitureSpace = layoutAlongFurnitureForm.m_nSpace;
				this.m_nAlongFurnitureOffset = layoutAlongFurnitureForm.m_nOffset;
				this.m_nAlongFurnitureNum = layoutAlongFurnitureForm.m_nNum;
				layoutAlongFurnitureForm.Close();
				base.DialogResult = DialogResult.OK;
			}
		}

		private List<FurnitureInfo> m_lstFurnitureInfo = new List<FurnitureInfo>();

		private SpaceFamilyDataReader m_sfdr = new SpaceFamilyDataReader();

		private Document m_CurrentDoc;

		private UIDocument m_uiDoc;

		private UIApplication m_uiApp;

		private List<Document> m_lstDoc = new List<Document>();

		private UserSetting m_userSetting = new UserSetting();

		private bool m_bPreview;

		public string m_strFamilySymbolName;

		public FamilySymbol m_famSym;

		public LayoutStyle m_LayoutStyle;

		public double m_dRelativeHeight;

		public int m_nAlongWallNum;

		public int m_nAlongWallSpace;

		public int m_nAlongWallToFace;

		public int m_nAlongWallToSide;

		public int m_nAlongFurnitureOffset;

		public int m_nAlongFurnitureSpace;

		public int m_nAlongFurnitureNum;
	}
}
